In [1]:
%matplotlib inline
In [44]:
import numpy as np
np.set_printoptions(precision=2, threshold=np.nan)
In [45]:
rng = np.random.RandomState(0)
In [46]:
mtx = rng.rand(32, 32)
mtx = (mtx + mtx.T) / 2.0
np.fill_diagonal(mtx, 1.0)
In [48]:
from scipy.sparse.csgraph import minimum_spanning_tree
In [49]:
from dyconnmap.graphs import threshold_eco, threshold_omst_global_cost_efficiency
In [56]:
mtx_mst = minimum_spanning_tree(mtx).todense()
In [57]:
nCIJtree, CIJtree, _, _, global_cost_eff_max, cost_max, cost, global_cost_eff = threshold_omst_global_cost_efficiency(mtx)
In [58]:
mtx_bin, mtx_eco, _ = threshold_eco(mtx)
In [59]:
import matplotlib.pyplot as plt
In [309]:
f, axes = plt.subplots(ncols=4, nrows=1, figsize=(10, 8), sharey=True)
im = axes[0].imshow(mtx, vmin=0.0, vmax=1.0, cmap=plt.cm.Spectral)
axes[0].set_title('Input', fontsize=14)
axes[1].imshow(mtx_mst, vmin=0.0, vmax=1.0, cmap=plt.cm.Spectral)
axes[1].set_title('MST', fontsize=14)
axes[2].imshow(CIJtree, vmin=0.0, vmax=1.0, cmap=plt.cm.Spectral)
axes[2].set_title('OMST', fontsize=14)
axes[3].imshow(mtx_eco, vmin=0.0, vmax=1.0, cmap=plt.cm.Spectral)
axes[3].set_title('Eco', fontsize=14)
f.subplots_adjust(right=0.8)
cbar_ax = f.add_axes([1.0, 0.35, 0.0125, 0.300])
cb = f.colorbar(im, cax=cbar_ax)
cb.set_label('Connectivity', fontsize=14)
plt.tight_layout()
plt.show()
In [312]:
nnz = 32 * 32
nnz_mst = np.count_nonzero(mtx_mst == 0)
nnz_omst = np.count_nonzero(CIJtree == 0)
nnz_eco = np.count_nonzero(mtx_eco == 0)
In [313]:
plt.figure()
plt.plot([nnz, nnz_mst, nnz_omst, nnz_eco], 'o-')
plt.axis('tight')
plt.ylabel('Non-zero elements', fontsize=12)
plt.xticks([0, 1, 2, 3], ['Max', 'MST', 'OMST', 'Eco'], rotation=45, fontsize=12)
plt.grid(alpha=0.25)
plt.title('Sparsity', fontsize=14)
plt.show()
In [ ]: